package com.example.cstr.controller;

import com.example.cstr.entity.EducationTrainProject;
import com.example.cstr.entity.Message;
import com.example.cstr.service.EducationTrainProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/EducationTrainProject")
@Api(tags = "教育培训项目")
public class EducationTrainProjectController {
    @Resource
    private EducationTrainProjectService educationTrainProjectService;

    @ApiOperation(value = "添加教育培训项目")
    @PostMapping("/add")
    public Message insertEducationTrainProject(EducationTrainProject educationTrainProject){
        return educationTrainProjectService.insertSelective(educationTrainProject)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "删除教育培训项目")
    @DeleteMapping("/delete")
    public Message deleteEducationTrainProject(Integer etpId){
        return educationTrainProjectService.deleteByPrimaryKey(etpId)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "修改教育培训项目")
    @PutMapping("/update")
    public Message updateEducationTrainProject(EducationTrainProject educationTrainProject){
        return educationTrainProjectService.updateByPrimaryKeySelective(educationTrainProject)>0?Message.success(null):Message.fail(null);
    }

    @ApiOperation(value = "根据教育培训项目id查询教育培训项目信息")
    @GetMapping("/select")
    public Message selectEducationTrainProject(Integer etpId){
        return educationTrainProjectService.selectByPrimaryKey(etpId)!=null?Message.success(null).add(educationTrainProjectService.selectByPrimaryKey(etpId)):Message.fail(null);
    }

    @ApiOperation(value = "查询所有教育培训项目信息")
    @GetMapping("/selectAll")
    public Message selectAllEducationTrainProject(){
        return Message.success(null).add(educationTrainProjectService.selectAllEducationTrainProject());
    }

    @ApiOperation(value = "分页查询-查询所有教育培训项目信息")
    @GetMapping("/pagingSearch")
    public Message PagingSearch(@RequestParam Integer pageNum,@RequestParam Integer size){
        return educationTrainProjectService.PagingSearch(pageNum,size);
    }

    @ApiOperation(value = "根据教育培训类别id查询其教育培训项目信息")
    @GetMapping("/selectByEtp_parent_id")
    public Message selectByEtp_parent_id(Integer etp_parent_id){
        return educationTrainProjectService.selectByEtp_parent_id(etp_parent_id)!=null?Message.success(null).add(educationTrainProjectService.selectByEtp_parent_id(etp_parent_id)):Message.fail(null);
    }

    @ApiOperation(value = "通过用户id查询教育培训项目id")
    @GetMapping("/selectEtpIdIdByWorkId")
    public Message selectEtpIdIdByWorkId(Integer workId){
        return educationTrainProjectService.selectEtpIdIdByWorkId(workId)!=null?Message.success(null).add(educationTrainProjectService.selectEtpIdIdByWorkId(workId)):Message.fail(null);
    }
}
